package cut;

import fj.P;

import java.util.Objects;

public class LogicStructure {

    public int sequence(int a, int b) {
        return a + b;
    }

    public boolean soloIf(int op) {
        if (op > 0)
            return true;
        return false;
    }

    public boolean ifElse(int op) {
        if (op > 18)
            return true;
        else
            return false;
    }

    public String multipleIf(int op) {
        if (op % 15 == 0)
            return "FizzBuzz";
        else if (op % 5 == 0)
            return "Buzz";
        else if (op % 3 == 0)
            return "Fizz";
        else {
            return Integer.toString(op);
        }

    }

    public int forLoop(int op) {
        int sum = 0;
        for (int i = 0; i < op; i++) {
            sum += i;
        }
        return sum;
    }

    public int array(int[] a) {
        for (int i = 0; i < a.length; i++) {
            if (a[i] != i) {
                return 0;
            }
        }
        return 1;
//        int[] fib = new int[a];
//        fib[0] = 1;
//        fib[1] = 1;
//        for (int i = 2; i < a; i++) {
//            fib[i] = fib[i - 1] + fib[i - 2];
//        }
//        return fib[a - 1];
    }

    public int string(String s) {
        if (s.length() == 1) {
            return 1;
        } else if (s.equals("hello")) {
            return 2;
        } else {
            if ((s + "baa").equals("aab" + s)) {
                return 3;
            } else if (Integer.toString(11).equals(s)) {
                return 4;
            } else {
                return 5;
            }
        }
    }

    public int ifElseUnreachable(int op) {
        if (op > 18) {
            if (op < 5) return 0;
            return 1;
        }else {
            return 2;
        }
    }

    public void loopSystem(int a,int b, int n){
        for(int j=0;j<n;j++){
            a+=b;
            if(j>0) System.out.print(" ");
            System.out.print(a);
            b = b * 2;
        }
    }

    public enum Color {
        RED, GREEN, BLUE;
    }

    public int enumTest(Color color) {
        if (color == Color.RED) {
            return 1;
        } else if (color == Color.GREEN) {
            return 2;
        } else if (color == Color.BLUE) {
            return 3;
        } else {
            return 0;
        }
    }

    public int forLoopEmbeded(int op) {
        int sum = 0;
        for (int i = 0; i < op; i++) {
            for (int j = 0; j < op; j++) {
                sum += i;
            }
        }
        return sum;
    }

    public int ifElseEmbeded(int op) {
        if (op > 18) {
            if (op < 5) return 0;
            return 1;
        }else {
            return 2;
        }
    }

    public int hello(int op) {
        if (op > 18) {
            if (op < 5) return 0;
            return 1;
        }else {
            return 2;
        }
    }

    public double floatTest(double a, double b) {
        int c = 2;
        if (a > b) {
            return a;
        } else if (b >= 1) {
            return b - 0.1f;
        } else if (a <= 0) {
            return a + b;
        }
        return a / b;
    }

    public int precisionTest(float a, float b, float c) {
        if (a+b+c == a+(b+c)) {
            return 1;
        } else {
            return 0;
        }
    }



    public BankPerson returnBankPerson(BankPerson bp){
        return bp;
    }


    public String giveBackMoney(int cardId, int balance, int backType) {
        BankPerson bp = new BankPerson();
        bp.setCardId(cardId);
        bp.setBalance(balance);
        bp.setBackType(backType);
        if(bp.getCardId()==102 && bp.balance>0){
            if (bp.getBackType() == 0 || bp.getBackType() == 1) {
                if(bp.balance>1000){
                    return "还款成功";
                }else{
                    return "余额不足";
                }
            }else return "返回";
        }else return "卡号错误或卡号姓名不一致或余额不足";
    }
}

class BankPerson{
    int cardId;
    int backType;

    int balance;

    public BankPerson() {}

    public int getBalance() {
        return balance;
    }

    public void setBalance(int balance) {
        this.balance = balance;
    }

    public int getCardId() {
        return cardId;
    }

    public void setCardId(int cardId) {
        this.cardId = cardId;
    }


    public int getBackType() {
        return backType;
    }

    public void setBackType(int backType) {
        this.backType = backType;
    }
}


